New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix browsable API not supporting multipart/form-data correctly #5176
Fix browsable API not supporting multipart/form-data correctly #5176
Conversation
- Autodetect missing boundary parameter for Content-Type header - textarea value normalises EOL chars to \n when multipart/form-data requires \r\n
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Couple of questions here - 1. could you make the reason for that particular regex more clear. 2. What's the intent of re.exec? 3. Could you include before/after screenshots in the PR description?
Looking good!
|
Not sure what I can show in a screenshot -- the UI hasn't changed and what happens is often dependent on your application code. Old behaviour with
|
// We need to add a boundary parameter to the header | ||
// We assume the first valid-looking boundary line in the body is correct | ||
// regex is from RFC 2046 appendix A | ||
var re = /^--([0-9A-Z'()+_,-./:=?]{1,70})[ \f\t\v\u00a0\u1680\u180e\u2000-\u200a\u2028\u2029\u202f\u205f\u3000\ufeff]*$/im; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we reduce the whitespace part of this regex to \s*
or something similar?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The boundary grouping isn't quite correct against the spec, as it can include " "
, it just can't do so at the end.
The only mandatory global parameter for the "multipart" media type is
the boundary parameter, which consists of 1 to 70 characters from a
set of characters known to be very robust through mail gateways, and
NOT ending with white space.
boundary := 0*69<bchars> bcharsnospace
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Now handles space in the boundary delimiter correctly (with a more obvious translation from the spec)
- Simplified whitespace to
\s*?
(the non-greedy qualifier because we want the$
to match the current line only and\s
includes\n
)
Re-tested locally with and without whitespace in the boundary; django handles this correctly too.
Great work on this! A couple of comments worth addressing there. |
191e418
to
6b8d601
Compare
(Comments should be addressed) |
// We need to add a boundary parameter to the header | ||
// We assume the first valid-looking boundary line in the body is correct | ||
// regex is from RFC 2046 appendix A | ||
var boundaryCharNoSpace = "[0-9A-Z'()+_,-./:=?"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The leading [
here looks wrong.
Lovely bit of enhancement - thanks! 😎 |
Fixes #1579